package influxdb

import (
	"github.com/influxdata/influxdb/client/v2"
	"log"
	"time"
)

const (
	DwellTime         = "dwelltime"
	DwellTimeBusiness = "dwelltime_business"
	Pack5dwellTime    = "pack5dwelltime"
	Pack60dwellTime   = "pack60dwelltime"
)

type Dwell struct {
	DateTime        time.Time
	ZoneId          int
	NumberServed    int
	SecondsOccupied int
}

func (c *Connect) InsertDwelltime(dwell []*Dwell, tableName string) int {
	var cPoint []*client.Point
	for _, value := range dwell {
		tags := map[string]string{
			"zoneid": string(value.ZoneId),
		}
		fields := map[string]interface{}{
			"numberserved":    value.NumberServed,
			"secondsOccupied": value.SecondsOccupied,
		}
		pt, err := client.NewPoint(tableName, tags, fields, value.DateTime)
		if err != nil {
			log.Println(err)
			return -1
		} else {
			cPoint = append(cPoint, pt)
		}
	}
	return c.insert(20000, cPoint)
}
